<?php
require_once 'XB/Router/Abstract.php';

class XB_Router_One extends XB_Router_Abstract {
	private static $_instance;
	
	public static function getInstance(){
		if (null === self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
	}
	
	private function __construct(){
		$this->setUri($_SERVER['REQUEST_URI']);
	}
	
	public function run(){
		$uri = $this->getUri();
		$uriArray = explode('/', $uri);
		@$this->setController($uriArray[1]);
		@$this->setAction($uriArray[2]);
		$this->exec();
	}
	
	private function exec(){
		$controller = $this->getController();
		$action = $this->getAction();
		try {
			require_once $controller . '.php';
			$controller = $controller.$this->getControllerSuffix();
			$action = $action.$this->getActionSuffix();
			$temp = new $controller;
			$temp->$action();
		} catch (Exception $e) {
			echo $e->getMessage();
			return ;
		}
	}
}

?>